package cn.kgc.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import cn.kgc.entity.SmsSeckillSkuRelation;
import cn.kgc.dto.SmsSeckillSkuRelationAddDTO;
import cn.kgc.dto.SmsSeckillSkuRelationUpdateDTO;
import cn.kgc.service.SmsSeckillSkuRelationService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import org.springframework.beans.BeanUtils;
import org.springframework.validation.annotation.Validated;
import cn.kgc.commons.vo.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import cn.kgc.entity.SmsSeckillSkuRelation;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

/**
 * (SmsSeckillSkuRelation)表控制层
 *
 * @author makejava
 * @since 2023-01-07 09:39:36
 */
@RestController
@RequestMapping("smsSeckillSkuRelation")
@Api
@Validated
public class SmsSeckillSkuRelationController {
    /**
     * 服务对象
     */
    @Resource
    private SmsSeckillSkuRelationService smsSeckillSkuRelationService;

    /**
     * 分页查询所有数据
     *
     * @param current 分页对象
     * @return 所有数据
     */
    @GetMapping("/list")
    @ApiOperation(value = "分页查询所有数据", produces = "application/json;charset=utf-8",
            httpMethod = "GET", response = Result.class)
    @ApiImplicitParam(name = "current", value = "当前页", paramType = "query", dataType = "int")
    @CrossOrigin
    public IPage<SmsSeckillSkuRelation> selectAll(@RequestParam(defaultValue = "1") int current,
                                                  @RequestParam(defaultValue = "5") int pageSize) {
        IPage<SmsSeckillSkuRelation> page = new Page(current, pageSize);

        return smsSeckillSkuRelationService.page(page);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    @CrossOrigin
    @ApiOperation(value = "通过主键查询单条数据", produces = "application/json;charset=utf-8",
            httpMethod = "GET", response = Result.class)
    @ApiImplicitParam(name = "id", value = "主键", paramType = "path", dataType = "int")
    public SmsSeckillSkuRelation selectOne(@PathVariable Serializable id) {
        return this.smsSeckillSkuRelationService.getById(id);
    }

    /**
     * 新增数据
     *
     * @param smsSeckillSkuRelationDTO 实体对象
     * @return 新增结果
     */
    @PostMapping("/insert")
    @ApiOperation(value = "新增", produces = "application/json;charset=utf-8",
            httpMethod = "POST", response = Result.class)
    @CrossOrigin
    public boolean insert(@RequestBody SmsSeckillSkuRelationAddDTO smsSeckillSkuRelationDTO) {
        SmsSeckillSkuRelation smsSeckillSkuRelation = new SmsSeckillSkuRelation();
        BeanUtils.copyProperties(smsSeckillSkuRelationDTO, smsSeckillSkuRelation);
        return this.smsSeckillSkuRelationService.save(smsSeckillSkuRelation);
    }

    /**
     * 修改数据
     *
     * @param smsSeckillSkuRelationDTO 实体对象
     * @return 修改结果
     */
    @PostMapping("/update")
    @ApiOperation(value = "修改信息", produces = "application/json;charset=utf-8",
            httpMethod = "POST", response = Result.class)
    @CrossOrigin
    public boolean update(@RequestBody SmsSeckillSkuRelationUpdateDTO smsSeckillSkuRelationDTO) {
        SmsSeckillSkuRelation smsSeckillSkuRelation = this.smsSeckillSkuRelationService.getById(smsSeckillSkuRelationDTO.getId());
        BeanUtils.copyProperties(smsSeckillSkuRelationDTO, smsSeckillSkuRelation);
        return this.smsSeckillSkuRelationService.updateById(smsSeckillSkuRelation);
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除结果
     */
    @DeleteMapping("/del/{id}")
    @ApiOperation(value = "根据主键删除信息", produces = "application/json;charset=utf-8",
            httpMethod = "DELETE", response = Result.class)
    @ApiImplicitParam(name = "id", value = "主键", paramType = "path", dataType = "int")
    @CrossOrigin
    public boolean delete(@PathVariable Long id) {
        return this.smsSeckillSkuRelationService.removeById(id);
    }
}
